require(["config"], function() {
	require(["jquery", "ejs"], function($, ejs) {

		/*let html = `<p><strong>供应商编码：</strong><span><%= prov_code %></span></p>
					<p><strong>供应商名称：</strong><span><%= prov_name %></span></p>
					<p><strong>联系人：</strong><span><%= linkman %></span></p>
					<p><strong>联系电话：</strong><span><%= telephone %></span></p>
					<p><strong>传真：</strong><span><%= fax %></span></p>
					<a href="providerList.html">返回</a>`;
*/
		var loc = location.href;
		var n1 = loc.length; //地址的总长度
		var n2 = loc.indexOf("="); //取得=号的位置
		const prov_code = decodeURI(loc.substr(n2 + 1, n1 - n2)); //从=号后面的内容

		const url = "/api/providers/find_by_prov_code";
		$.getJSON(url, {
			prov_code
		}, (data) => {
			if(data.res_code === 1) {
				$("#providerId").val(data.res_body.data.prov_code);
				$("#providerName").val(data.res_body.data.prov_name);
				$("#people").val(data.res_body.data.linkman);
				$("#phone").val(data.res_body.data.telephone);
				$("#fax").val(data.res_body.data.fax);
				$("#id").val(data.res_body.data._id);

				$(".btn-save").on("click", function() {
					const url = "/api/providers/modify";
					const data = $(".updateProv-form").serialize();
					$.post(url, data, (data) => {
						console.log(data)
					});
				});

				//				const ht = ejs.render(html, data.res_body.data);
				//				$(".providerView").html(ht);
			}
		});
	});
});